package com.dal.constant;

import com.dal.module.account.paramcheck.HeiTaoParamChecker;
import com.jfinal.core.Controller;
import org.error.LoginErrorCode;

import com.dal.module.account.paramcheck.ParamChecker;
import com.dal.module.account.paramcheck.LocalTestParamChecker;
import com.sojoys.artifact.tools.ToolError;

import java.util.Map;

/**
 * 参数检查器枚举
 * Created by fxf on 2017/6/26.
 */
public enum ParamCheckerEnum {

	LOCAL_TEST(ChannelType.LOCAL_TEST,new LocalTestParamChecker()),
    HEI_TAO(ChannelType.HEI_TAO,new HeiTaoParamChecker()),
    ;

	String channelTag;
    ParamChecker checker;

    ParamCheckerEnum(String channelTag, ParamChecker checker) {
        this.channelTag = channelTag;
        this.checker = checker;
    }

    public static void check(String channelTag,Controller controller, Map outParam){
        getParamChecker(channelTag).check(controller,outParam);
    }

    private static ParamChecker getParamChecker(String channelTag){
        for (ParamCheckerEnum paramCheckerEnum : values()) {
            if (paramCheckerEnum.channelTag.equals(channelTag)) {
                return paramCheckerEnum.checker;
            }
        }
        ToolError.isAndTrue(LoginErrorCode.PARAM_CHECKER_TYPE_ERR,true);
        return null;
    }
}
